<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Category extends BaseModel
{
    use HasFactory;
    public $timestamps = false;
    protected $table = 'sys_category';
    protected $guarded = [];


    public function dicts()
    {
        return $this->hasMany(Dict::class, 'category_id');
    }

    public function children()
    {
        return $this->hasMany(get_class($this), 'pId');
    }

    public function allChildren()
    {
        return $this->children()->with('allChildren');
    }

    public function _deleting()
    {
        foreach ($this->children()->get() as $k => $v) {
            $v->delete();
        }
    }
}
